package com.jiji.miaosha.mapper.provide;

import com.jiji.miaosha.entity.Item;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class ItemMapperProvider extends BaseProvider{

    public String insertSelective(final Map<String, Object> map) {
        Item item = (Item) map.get("item");
        SQL sql = new SQL() {
            {
                INSERT_INTO(ITEM.trim());
                if (item.getTitle() != null) {
                    VALUES("title", "'" + item.getTitle() + "'");
                }

                if (item.getPrice() != null) {
                    VALUES("price", String.valueOf(item.getPrice()));

                }
                if (item.getDescription() != null) {
                    VALUES("description", "'" + item.getDescription() + "'");
                }
                if (item.getSales() != null) {
                    VALUES("sales", String.valueOf(item.getSales()));
                }
                if (item.getImgUrl() != null) {
                    VALUES("img_url", "'" + item.getImgUrl() + "'");
                }

            }
        };
        return sql.toString();
    }
}
